"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
function Demo(target) {
    console.log(target);
}
let Person = class Person {
    constructor(name, age) {
        this.name = name;
        this.age = age;
    }
};
Person = __decorate([
    Demo
], Person);
// 应用举例：定义一个装饰器，实现Person实例调用toString时返回JSON.stringify的执行结果
function CustomString(target) {
    target.prototype.toString = function () {
        return JSON.stringify(this);
    };
    // 封锁  对象上的原型不允许操作
    // Object.seal(target.prototype)
}
let Person1 = class Person1 {
    constructor(name, age) {
        this.name = name;
        this.age = age;
    }
};
Person1 = __decorate([
    CustomString
], Person1);
const p1 = new Person1('张三', 18);
console.log(p1.toString());
/**
 * 关于返回值：
 * 类装饰器有返回值：若类装饰器返回一个新的类，那这个新类将替换掉被装饰的类。
 * 类装饰器无返回值：若类装饰器无返回值或者返回undefined，那被装饰的类不会被替换。
 *
 */
function Demo2(target) {
    return class {
        test() {
            console.log(200);
            console.log(300);
            console.log(400);
        }
    };
}
let Person2 = class Person2 {
    test() {
        console.log(100);
    }
};
Person2 = __decorate([
    Demo2
], Person2);
console.log(Person2);
